package com.calvin.study.observer.event;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class ListenerTwo implements SmartApplicationListener {

	@Override
	public void onApplicationEvent(ApplicationEvent event) {
		if (event instanceof ContextRefreshedEvent) {
			log.info("监听到 ContextRefreshedEvent...");
		}
		if (event instanceof MyEvent) {
			log.info("监听到 MyEvent...");
			MyEvent myEvent = (MyEvent) event;
			System.out.println("时间：" + myEvent.getTime() + " 信息：" + myEvent.getMsg());
		}

	}

	@Override
	public int getOrder() {
		return 0;
	}

	@Override
	public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
		return eventType == MyEvent.class || eventType == ContextRefreshedEvent.class;
	}

}
